package com.nvwa.boot.stater.web.environment;

/**
 * 判断服务所在环境
 */
public class EnvironmentChecker {

    private final String DEV = "dev";
    private final String TEST = "test";
    private final String PROD = "prod";

    private final EnvironmentProperties properties;

    public EnvironmentChecker(EnvironmentProperties properties) {
        this.properties = properties;
    }

    public boolean isDevelopment() {
        return DEV.equalsIgnoreCase(properties.getActive());
    }

    public boolean isTesting() {
        return TEST.equalsIgnoreCase(properties.getActive());
    }

    public boolean isProduction() {
        return PROD.equalsIgnoreCase(properties.getActive());
    }

    public String getEnvironmentActiveCode() {
        if (this.isDevelopment()) return DEV;
        if (this.isTesting()) return TEST;
        if (this.isProduction()) return PROD;
        return "unknown";
    }
}